<template>
  <a-input v-model="name" v-on="$listeners" v-bind="$attrs"></a-input>
</template>

<script>

  import { getAction } from '@/api/manage'
  import YchConstant from "@/api/YchConstant";

  export default {
    name: 'SysOrgName',
    props: {
      value: {
        type: String,
        default: null
      }
    },
    data () {
      return {
        name: null,
        url: {
          queryPathNameById: YchConstant.PREFIX_SYSTEM + '/sysOrg/queryPathNameById',
        }
      }
    },
    watch: {
      value: {
        handler () {
          this.loadData()
        },
        immediate: true
      }
    },
    methods: {
      loadData () {
        if (!this.value) {
          this.name = null
          return
        }
        getAction(this.url.queryPathNameById, { id: this.value }).then((res) => {
          if (res.success) {
            this.name = res.result
          } else {
            this.name = null
          }
        }).finally(() => {
        })
      }
    }
  }
</script>
